<section>
	<div class="page-header">
		<h2><?php echo $title; ?></h2>
	</div>
	
	<table class="zebra-striped">
		<thead>
			<tr>
				<th width="30">ID</th>
				<th>Name</th>
				<th width="75">Actions</th>
			</tr>
		</thead>
		<tbody>
			<?php
				$tr = '';
				
				foreach ($categories as $cat)
				{
					if ($cat['ancestor'] == 0)
					{
						$tr .= '<tr><td>' . $cat['content_category_id'] . '</td><td>' . $cat['name'] . '</td>';
						$tr .= '<td>' . anchor('contents/edit_category/' . $cat['content_category_id'], 'Edit') . ' &nbsp; ' . anchor('contents/delete_category/' . $cat['content_category_id'], 'Delete', array('class' => 'delete')) . '</td></tr>';
						
						foreach ($categories as $cat2)
						{
							if ($cat2['ancestor'] == $cat['content_category_id'])
							{
								if ($cat2['parent_category'] == 0)
								{
									$tr .= '<tr><td>' . $cat2['content_category_id'] . '</td><td>&mdash; ' . $cat2['name'] . '</td>';
									$tr .= '<td>' . anchor('contents/edit_category/' . $cat2['content_category_id'], 'Edit') . ' &nbsp; ' . anchor('contents/delete_category/' . $cat2['content_category_id'], 'Delete', array('class' => 'delete')) . '</td></tr>';
									
									foreach ($categories as $cat3)
									{
										if ($cat3['parent_category'] == $cat2['content_category_id'])
										{
											$tr .= '<tr><td>' . $cat3['content_category_id'] . '</td><td>&nbsp;&nbsp;&nbsp;&mdash; ' . $cat3['name'] . '</td>';
											$tr .= '<td>' . anchor('contents/edit_category/' . $cat3['content_category_id'], 'Edit') . ' &nbsp; ' . anchor('contents/delete_category/' . $cat3['content_category_id'], 'Delete', array('class' => 'delete')) . '</td></tr>';
										}
									}
								}
							}
						}
					}
				}
				
				echo $tr;
			?>
		</tbody>
	</table>
	
</section>

<script>
	$('table .delete').click(function() {
        
        del = $(this);
        
        buildModal({
            modalID: 'deleteCat',
            modalHeader: 'Delete Category',
            modalBody: 'Are you sure that you want to delete this category?',
            btnPrimaryText: 'Delete',
			ajaxUrl: del.attr('href')
        });
        
        return false;
    });
</script>